<template>
  <div class="container">
    <div class="row">
      <div class="col-xs-12 col-sm-6 logo"><a href="/"><img width="100%" src="../assets/logo.jpg"></a></div>
      <div class="col-xs-12 col-sm-6 search">
        <form class="navbar-form navbar-left">
          <div class="input-group">
            <input v-model="text" type="text" class="form-control" style="width: 320px;" placeholder="搜索" />
            <span @click="searchCommodity" class="input-group-addon">
              <a href="javascript:;">
                <span class="glyphicon glyphicon-search"></span>
              </a>
            </span>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      text: null
    }
  },
  methods: {
    searchCommodity () {
      if (!this.text) {
        return
      }
      this.$store.state.meunName = this.text
      if (this.$route.name !== 'commodityList') {
        this.$router.push({
          path: '/',
          name: 'commodityList',
          params: {
            text: this.text
          }
        })
      } else {
        this.$store.state.getSearch = this.text
      }
      this.text = ''
    }
  }
}
</script>

<style lang="less" scoped>
.row{
  .logo{
    height: 90px;
    @media screen and (max-width:780px){
      text-align: center;
    }
    img{
      margin-top: 10px;
    }
  }
  .search{
    height: 90px;
    .navbar-form{
      margin-top: 20px;
    }
  }

}
.input-group{
  height: 50px;
  width: 100%;
  .form-control{
    width: 320px;
    height: 50px;
    @media screen and (max-width:780px){
      width:100% !important;
    }
  }
}
.input-group-addon{
  background-color: #333;
  width: 50px !important;
  border: none;
  .glyphicon{
    color: #fff;
    font-size: 20px;
    &:hover{
      color: #b7b7b7;
    }
  }
}
</style>
